package com.caine.filter.handler;

import com.caine.common.entity.R;
import com.caine.common.tool.PrintTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: CaineZhu
 * @Description: 访问受限处理
 * @Date: Created in 14:44 2021/1/8
 * @Modified By:
 */
@Slf4j
public class AuthAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        log.error("访问受限异常", httpServletRequest.getRequestURL());
        PrintTool.printMsg(httpServletResponse,R.error("访问受限"));
    }
}
